/*
 * Created by JFormDesigner on Sun Dec 27 10:13:40 CST 2020
 */

package cn.fourhundredandeighteen.view.AdminView.RewardView.addReward;

import cn.fourhundredandeighteen.controller.SubjectController;
import cn.fourhundredandeighteen.entity.Subject;
import cn.fourhundredandeighteen.utill.Result;
import cn.fourhundredandeighteen.view.Component.Button;
import cn.fourhundredandeighteen.view.Component.Container;

import java.awt.*;
import java.awt.event.*;
import java.util.Date;
import java.util.List;
import javax.swing.*;

/**
 * @author Br.S
 */
public class addRewardInfo extends JPanel {
    public addRewardInfo() {
        initComponents();
    }

    private void button1ActionPerformed(ActionEvent e) {
        // TODO add your code here

    }

    private void button1MouseClicked(MouseEvent e) {
        // TODO add your code here
        try{
            Subject subject = new Subject();
            subject.setSubjectId(1L);
            subject.setSubjectName(textField2.getText());
            subject.setSubjectGrade(textField3.getText());
            subject.setSubjectLevel(Integer.valueOf(textField4.getText()));
            subject.setSubjectCategory(textField5.getText());
            subject.setSubjectCount(Integer.valueOf(textField6.getText()));
            subject.setUpdateTime(new Date());
            subject.setSubjectTime(new Date());
            subject.setCreateTime(new Date());
            SubjectController subjectController = new SubjectController();
            Long[] longs = new Long[Integer.valueOf(textField6.getText())];
            for (int i =0; i < Integer.valueOf(textField6.getText()); i++) {
                String inputDialog = JOptionPane.showInputDialog("请输入第个"+i+"获奖学生的学号");
                longs[i]= Long.valueOf(inputDialog);
            }
            Result result = subjectController.setSubject(subject);//添加获奖信息
            Result<List<Subject>> allSubjectInfo = subjectController.getAllSubjectInfo();
            //  System.out.println(allSubjectInfo.getData().get(allSubjectInfo.getData().size()-1).getSubjectId());//获取新增课程ID】
            if (result.getMassage()=="SUCCESS") {
                //设置获奖人员
                Result result1 = subjectController.setSubjectUsers(allSubjectInfo.getData().get(allSubjectInfo.getData().size()-1).getSubjectId(), longs);
                if (result1.getMassage() == "SUCCESS") {
                    JOptionPane.showMessageDialog(null, "修改成功");
                    Container.getInstance().upDatePage();
                }
            }
        }catch (Exception exception){
            exception.printStackTrace();
            JOptionPane.showMessageDialog(null, "请检查参数");
        }
    }


    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        label1 = new JLabel();
        textField1 = new JTextField();
        label2 = new JLabel();
        textField2 = new JTextField();
        label3 = new JLabel();
        textField3 = new JTextField();
        label4 = new JLabel();
        textField4 = new JTextField();
        label5 = new JLabel();
        textField5 = new JTextField();
        label6 = new JLabel();
        textField6 = new JTextField();
        button1 = new Button();
        label9 = new JLabel();

        //======== this ========
        setLayout(new GridBagLayout());
        ((GridBagLayout)getLayout()).columnWidths = new int[] {87, 69, 0, 0, 222, 0, 0, 0};
        ((GridBagLayout)getLayout()).rowHeights = new int[] {43, 55, 55, 51, 55, 55, 54, 37, 0};
        ((GridBagLayout)getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
        ((GridBagLayout)getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};

        //---- label1 ----
        label1.setText("Id");
        label1.setMaximumSize(new Dimension(23, 25));
        add(label1, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 25, 15), 0, 0));

        //---- textField1 ----
        textField1.setText("id\u7531\u7cfb\u7edf\u81ea\u52a8\u751f\u6210");
        add(textField1, new GridBagConstraints(2, 1, 3, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 25, 15), 0, 0));

        //---- label2 ----
        label2.setText("\u6bd4\u8d5b\u540d\u79f0");
        add(label2, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 25, 15), 0, 0));
        add(textField2, new GridBagConstraints(2, 2, 3, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 25, 15), 0, 0));

        //---- label3 ----
        label3.setText("\u83b7\u5956\u7ea7\u522b");
        add(label3, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 25, 15), 0, 0));
        add(textField3, new GridBagConstraints(2, 3, 3, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 25, 15), 0, 0));

        //---- label4 ----
        label4.setText("\u6bd4\u8d5b\u7ea7\u522b");
        add(label4, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 25, 15), 0, 0));
        add(textField4, new GridBagConstraints(2, 4, 3, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 25, 15), 0, 0));

        //---- label5 ----
        label5.setText("\u6bd4\u8d5b\u7c7b\u522b");
        add(label5, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 25, 15), 0, 0));
        add(textField5, new GridBagConstraints(2, 5, 3, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 25, 15), 0, 0));

        //---- label6 ----
        label6.setText("\u4eba\u6570");
        add(label6, new GridBagConstraints(1, 6, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 25, 15), 0, 0));
        add(textField6, new GridBagConstraints(2, 6, 3, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 25, 15), 0, 0));

        //---- button1 ----
        button1.setText("\u6dfb\u52a0");
        button1.addActionListener(e -> {
			button1ActionPerformed(e);
			button1ActionPerformed(e);
		});
        button1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button1MouseClicked(e);
            }
        });
        add(button1, new GridBagConstraints(2, 7, 2, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 15), 0, 0));
        add(label9, new GridBagConstraints(4, 7, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 15), 0, 0));
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel label1;
    private JTextField textField1;
    private JLabel label2;
    private JTextField textField2;
    private JLabel label3;
    private JTextField textField3;
    private JLabel label4;
    private JTextField textField4;
    private JLabel label5;
    private JTextField textField5;
    private JLabel label6;
    private JTextField textField6;
    private JButton button1;
    private JLabel label9;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
